package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;
@RestController
public class UploadController {
    @Autowired
    private UploadService uploadService;
    @PostMapping("/upload")
    public Result upload(MultipartFile file) throws Exception {
//        //文件原始名称
//        String originalFilename = file.getOriginalFilename();
//
//        //截取扩展名
//        String extName = originalFilename.substring(originalFilename.lastIndexOf("."));
//
//        String uuid = UUID.randomUUID().toString();
//
//        String fileName = uuid+extName;
//
//        file.transferTo(new File("D:\\"+fileName));

        String url = uploadService.upload(file);

        return Result.success(url);
    }
}
